package com.qbadroid;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class MainMenu extends Activity {

	private Button parserButton;
	private Button intentButton;
	private Button dbButton;
	private Button audioButton;
	private TextView methods;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.menu);
		
		parserButton = (Button)findViewById(R.id.Button01);
		intentButton = (Button)findViewById(R.id.Button02);
		dbButton = (Button)findViewById(R.id.Button03);
		audioButton = (Button)findViewById(R.id.audioButton);
		methods = (TextView)findViewById(R.id.TextView04);
		
		methods.setText(methods.getText() + "\nonCreate()");
		
		parserButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(MainMenu.this, MainActivity.class),1);
			}
		});
		
		intentButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("tel:123")));
			}
		});
		
		dbButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startActivityForResult(new Intent(MainMenu.this, DatabaseActivity.class),2);
			}
		});
		
		audioButton.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				startActivity(new Intent(MainMenu.this, AudioActivity.class));
			}
		});
	}
	
	@Override
    protected void onPause() {
        super.onPause();
        methods.setText(methods.getText() + "\nonPause()");
    }
 
    @Override
    protected void onRestart() {
        super.onRestart();
        methods.setText(methods.getText() + "\nonRestart()");
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        methods.setText(methods.getText() + "\nonResume()");
    }
 
    @Override
    protected void onStart() {
        super.onStart();
        methods.setText(methods.getText() + "\nonStart()");
    }
 
    @Override
    protected void onStop() {
        super.onStop();
        methods.setText(methods.getText() + "\nonStop()");
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    	if(requestCode == 1)
    		methods.setText(methods.getText() + "\n" + data.getStringExtra("result"));
    	else if(requestCode == 2)
    		methods.setText(methods.getText() + "\n" + data.getStringExtra("result"));
    	super.onActivityResult(requestCode, resultCode, data);
    }
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {

    	MenuInflater inflater = getMenuInflater();
    	inflater.inflate(R.menu.menu, menu);

    	return super.onCreateOptionsMenu(menu);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
  
    	if(item.getItemId() == R.id.about)
    	{
    		AlertDialog alert = new AlertDialog.Builder(this).create();
    		alert.setTitle("About");
    		alert.setButton("OK", new DialogInterface.OnClickListener() {
    			
    			@Override
    			public void onClick(DialogInterface dialog, int which) {
    				// TODO Auto-generated method stub
    				
    			}
    		});
    		alert.show();
    		return true;
    	}
    	else if(item.getItemId() == R.id.exit)
    	{
    		finish();
    		return true;
    	}
    	else
    		return false;
    }
}
